﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;


public struct PatientId
{
    public string Pid;
}


[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
    private PatientId patient;

    public Service () {
        patient.Pid = "";
    }

    private void AssignValues(string pname, string pwd)
    {

        SqlConnection conn = null;
        SqlDataReader rdr = null;

        string PName = pname;
        string Pwd = pwd;

        try
        {
            conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDbConn2"].ToString());
            //Server=localhost;DataBase=PatientRecord;Integrated Security=SSPI");
            conn.Open();

            SqlCommand cmd = new SqlCommand("logincheck", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@PName", PName));
            cmd.Parameters.Add(new SqlParameter("@Pwd", Pwd));


            rdr = cmd.ExecuteReader();
            if (rdr.Read())
            {
                
                    patient.Pid = rdr.GetString(0);
                
            }
            else
            {
                patient.Pid = "";
            }


        }

        finally
        {
            if (conn != null)
            {
                conn.Close();
            }
            if (rdr != null)
            {
                rdr.Close();
            }

        }


    }


    [WebMethod]
   public PatientId GetPatientId(string pname, string pwd)
    {
        AssignValues(pname, pwd);
        PatientId PIDDetails = new PatientId();

        PIDDetails.Pid = patient.Pid;

        return PIDDetails;

    }

    
}


